package com.xiaoxing.salesclient.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.flyco.tablayout.SlidingTabLayout;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.xiaoxing.salesclient.di.component.DaggerJiFenShangChengComponent;
import com.xiaoxing.salesclient.di.module.JiFenShangChengModule;
import com.xiaoxing.salesclient.mvp.contract.JiFenShangChengContract;
import com.xiaoxing.salesclient.mvp.model.entity.ProductCateList;
import com.xiaoxing.salesclient.mvp.presenter.JiFenShangChengPresenter;
import com.xiaoxing.salesclient.mvp.ui.fragment.ChanPinJiaGeTabFragment;
import com.xiaoxing.salesclient.mvp.ui.fragment.FragmentHome;
import com.xiaoxing.salesclient.mvp.ui.fragment.JiFenShangChengTabFragment;

import java.util.ArrayList;
import java.util.List;

import me.jessyan.armscomponent.commonres.utils.SlidingTabLayoutUtil;
import me.jessyan.armscomponent.commonres.utils.ToolbarUtils;
import me.jessyan.armscomponent.commonsdk.core.RouterHub;
import xiaoxing.com.salesclient.R;

import static com.jess.arms.utils.Preconditions.checkNotNull;


@Route(path = RouterHub.SALES_CLIENT_JI_FEN_SHANG_CHENG_ACTIVITY)
public class JiFenShangChengActivity extends BaseActivity<JiFenShangChengPresenter> implements JiFenShangChengContract.View {

//    private final String[] mTitles = {"彩妝", "化妝品", "3C手機", "日常保健", "日用品"};

    private List<ProductCateList.DataBean> dataBeanList;
    private SlidingTabLayout mSlidingTabLayout;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerJiFenShangChengComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .jiFenShangChengModule(new JiFenShangChengModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_ji_fen_shang_cheng; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

        ToolbarUtils.initToolbarTitleBack(this, "積分商城");


        mPresenter.productCateList();

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public void productCateListSuccessed(ProductCateList productCateList) {
        dataBeanList = productCateList.getData();

        if (dataBeanList != null && dataBeanList.size() > 0) {

            ArrayList<Fragment> mFragments = new ArrayList<>();
            String[] mTitles = new String[dataBeanList.size()];

            for (int i = 0; i < dataBeanList.size(); i++) {
                mTitles[i] = dataBeanList.get(i).getType_name();
                mFragments.add(JiFenShangChengTabFragment.newInstance(dataBeanList.get(i).getType_id()));
            }

            mSlidingTabLayout = SlidingTabLayoutUtil.init(this, mTitles, mFragments);
        }

    }
}
